package com.qiyi.player.wonder.body.model.remote
{
   import flash.net.URLLoader;
   import flash.net.URLRequest;
   import com.qiyi.player.base.logging.ILogger;
   import com.qiyi.player.wonder.common.config.SystemConfig;
   import flash.events.Event;
   import flash.events.IOErrorEvent;
   import flash.events.SecurityErrorEvent;
   import gs.TweenLite;
   import com.adobe.serialization.json.JSON;
   import com.qiyi.player.base.logging.Log;
   
   public class BonusDoubleInfo extends Object
   {
      
      public function BonusDoubleInfo() {
         this._log = Log.getLogger("com.qiyi.player.wonder.body.model.actors.parts.BonusDoubleInfo");
         super();
      }
      
      private var _loader:URLLoader;
      
      private var _request:URLRequest;
      
      private var _albumID:String = "";
      
      private var _tvID:String = "";
      
      private var _channelID:String = "";
      
      private var _vvSourceID:String = "";
      
      private var _backFun:Function = null;
      
      private var _isReady:Boolean = false;
      
      private var _log:ILogger;
      
      private var _bounsDoubleInfoJSON:Object;
      
      public function get isReady() : Boolean {
         return this._isReady;
      }
      
      public function startLoad(param1:String, param2:String, param3:String, param4:String, param5:Function) : void {
         var _loc6_:String = null;
         if((param1) && !(param1 == this._albumID))
         {
            this.destroyLoader();
            this._isReady = false;
            this._albumID = param1;
            this._tvID = param2;
            this._vvSourceID = param3;
            this._channelID = param4;
            this._backFun = param5;
            _loc6_ = SystemConfig.BONUS_DOUBLE_INFO_URL + "?albumId=" + this._albumID + "&tvId=" + this._tvID + "&vvSourceId=" + this._vvSourceID + "&channelId=" + this._channelID + "&t=" + Math.random();
            this._request = new URLRequest(_loc6_);
            this._loader = new URLLoader();
            this._loader.addEventListener(Event.COMPLETE,this.onCompleteHandler);
            this._loader.addEventListener(IOErrorEvent.IO_ERROR,this.onErrorHander);
            this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onErrorHander);
            this._loader.load(this._request);
            this._log.info("bounsDoubleInfoJSON start request json data : " + _loc6_);
            TweenLite.delayedCall(2,this.delayedRequest);
         }
      }
      
      private function delayedRequest() : void {
         if(this._isReady)
         {
            return;
         }
         this.destroyLoader();
         this._isReady = false;
         var _loc1_:String = SystemConfig.BONUS_DOUBLE_INFO_URL + "?albumId=" + this._albumID + "&tvId=" + this._tvID + "&vvSourceId=" + this._vvSourceID + "&channelId=" + this._channelID + "&t=" + Math.random();
         this._request = new URLRequest(_loc1_);
         this._loader = new URLLoader();
         this._loader.addEventListener(Event.COMPLETE,this.onCompleteHandler);
         this._loader.addEventListener(IOErrorEvent.IO_ERROR,this.onErrorHander);
         this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onErrorHander);
         this._loader.load(this._request);
         this._log.info("bounsDoubleInfoJSON delayed request json data : " + _loc1_);
      }
      
      private function onCompleteHandler(param1:Event) : void {
         var event:Event = param1;
         this._isReady = true;
         try
         {
            this._bounsDoubleInfoJSON = com.adobe.serialization.json.JSON.decode(this._loader.data);
            if(this._bounsDoubleInfoJSON.code == "A00000" && this._bounsDoubleInfoJSON.data > 0)
            {
               this._backFun(this._bounsDoubleInfoJSON.data.toString());
               this._log.info("bounsDoubleInfoJSON respond call backFunction : " + this._bounsDoubleInfoJSON.data);
            }
            this._log.info("bounsDoubleInfoJSON respond json data : " + this._bounsDoubleInfoJSON.data);
         }
         catch(e:Error)
         {
            _bounsDoubleInfoJSON = null;
            _log.debug("bounsDoubleInfoJSON json data analyze fail : " + _albumID);
         }
      }
      
      private function onErrorHander(param1:*) : void {
      }
      
      private function destroyLoader() : void {
         if(this._loader)
         {
            this._loader.removeEventListener(Event.COMPLETE,this.onCompleteHandler);
            this._loader.removeEventListener(IOErrorEvent.IO_ERROR,this.onErrorHander);
            this._loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onErrorHander);
            try
            {
               this._loader.close();
            }
            catch(e:Error)
            {
            }
            this._request = null;
            this._loader = null;
         }
      }
      
      public function get bounsDoubleInfoJSON() : Object {
         return this._bounsDoubleInfoJSON?this._bounsDoubleInfoJSON:null;
      }
   }
}
